from django.shortcuts import render
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework.generics import GenericAPIView
# Create your views here.
from . import serializers
from .models import Qusetions, Answer, Label
from rest_framework.generics import ListAPIView, RetrieveAPIView

# GET /{host}/questions/
# GET /{host}/questions/{id}


class QuestionAPIView(ListAPIView):
    # permission_classes = (IsAuthenticated,)
    queryset = Qusetions.objects.all()
    serializer_class = serializers.QuestionsSerializer



class AskAPIView(RetrieveAPIView):

    # permission_classes = (IsAuthenticated,)
    queryset = Qusetions.objects.all()
    serializer_class = serializers.QuestionsSerializer

    # def get_queryset(self):
    #     pk = self.kwargs['pk']
    #
    #     # queryset = Qusetions.objects.get(question_id=question_id).subs.all()
    #     return queryset


class LabelAPIView(ListAPIView):

    permission_classes = (IsAuthenticated,)
    serializer_class = serializers.LabelSerializer
    queryset = Label.objects.all()


class LabelDatailAPIView(ListAPIView):

    permission_classes = (IsAuthenticated,)
    serializer_class = serializers.LabelSerializer
    def get_queryset(self):
        id = self.kwargs['pk']
        queryset = Label.objects.filter(id=id).all()
        # queryset = Qusetions.objects.get(question_id=question_id).subs.all()
        return queryset


class CreateQuestionAPIView(GenericAPIView):
    serializer_class = serializers.SubmitSerializer

    def post(self, request):
        serializer = serializers.SubmitSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serializer.data)



